/*****************************************************************************************
This file is a part of Arise library.

This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.

This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Lesser General Public License for more details.

Arise Engine		ScriptEngine.cpp

					E-mail:		arise_engine@mail.ru

created:			22.01.2008
last changes:		05.02.2008
*****************************************************************************************/
#include "stdafx.h"

void CompileAndExecute(const std::string& script_name);
void Compile(const std::string& script_name);
void Execute(const std::string& script_name);


ScriptEngine::ScriptEngine()
{
}
ScriptEngine::~ScriptEngine()
{
}


void ScriptEngine::ConfigureEngine()
{
	IScriptEngine::ConfigureEngine();

	//	Configure the script engine with all the project-specific functions, 
	//	and variables that the script should be able to use.

	asIScriptEngine* engine = GetDevice();
	if(!engine) return;

	int r = -1;
	r = engine->RegisterGlobalFunction("void CompileExecute(const string& script_name)", asFUNCTION(CompileAndExecute), asCALL_CDECL); P(r);
	r = engine->RegisterGlobalFunction("void Compile(const string& script_name)", asFUNCTION(Compile), asCALL_CDECL); P(r);
	r = engine->RegisterGlobalFunction("void Execute(const string& script_name)", asFUNCTION(Execute), asCALL_CDECL); P(r);
}


void CompileAndExecute(const std::string& script_name)
{
	if(script_name.empty()) return;

	//	script call: compile and execute script with push stack
	g_host.m_script_engine.CompileExecute(script_name, true);
}


void Compile(const std::string& script_name)
{
	if(script_name.empty()) return;

	//	script call: compile single script document
	g_host.m_script_engine.CompileScript(script_name);
}


void Execute(const std::string& script_name)
{
	if(script_name.empty()) return;

	//	script call: execute script with push stack
	g_host.m_script_engine.ExecuteScript(script_name, true);
}